/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans;

import Entities.Modelerdp;
import Entities.Utilisateur;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Dell
 */
@Stateless
@LocalBean
public class RdPManager {

    @PersistenceContext(unitName = "PetriNetSimulator-ejbPU")
    private EntityManager em;

    public List<Modelerdp> getAllRdpModels() {
        Query query = em.createNamedQuery("Modelerdp.findAll");
        return query.getResultList();
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public Modelerdp update(Modelerdp modelerdp) {
        return em.merge(modelerdp);
    }

    public void persist(Object object) {
        em.persist(object);
    }

    public Modelerdp savemodel(String login, String idm, Date datec, String matricepre, String matricepost) {
        Utilisateur u = em.find(Utilisateur.class, login);
        Modelerdp m = new Modelerdp();
        m.setLogin(u);
        m.setDatec(datec);
        m.setIdm(idm);
        m.setMatricepre(matricepre);
        m.setMatricepost(matricepost);
        u.getModelerdpCollection().add(m);
        em.persist(m);
        return m;
    }

   
    public void remove(Modelerdp rdp) {
        em.remove(em.merge(rdp));
    }
}
